/*
 * @Author: master
 * @Date: 2022-04-08 18:50:05
 * @LastEditTime: 2022-04-08 19:10:58
 * @Description: proxy 代理服务
 */
import _ from 'lodash';
/**
 * @param {Object} viteConfig
 * @returns
 */
export default function proxy(viteConfig) {
  const proxy = {};
  if (viteConfig.proxy && _.isObject(viteConfig.proxy)) {
    _.forIn(viteConfig.proxy, (value, key) => {
      if (_.isObject(value)) {
        proxy[key] = { ...value };
        const arg = new RegExp(`^${key}`);
        proxy[key].rewrite = path => path.replace(arg, '');
      } else {
        proxy[key] = value;
      }
    });
  }
  return {
    ...proxy,
  };
}
